package com.irdstudio.efp.console.api.rest;

import java.util.List;
import java.util.Map;

import com.irdstudio.basic.framework.core.constant.PubConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.irdstudio.efp.console.service.facade.PrdSoltInService;
import com.irdstudio.efp.console.service.vo.PrdSoltInVO;
import com.irdstudio.efp.e4a.service.facade.SRoleDataRuleService;
import com.irdstudio.basic.framework.core.constant.DataRuleType;
import com.irdstudio.basic.framework.core.constant.ResponseData;
import com.irdstudio.basic.framework.web.controller.AbstractController;

/**
 * Controller：产品进件插槽参数
 * 
 * @author huangwb
 * @since 2018年12月26日 下午7:19:03
 * @version 1.0
 */
@RestController
@RequestMapping("/api")
public class PrdSoltInController extends AbstractController {
	@Autowired
	@Qualifier("sRoleDataRuleService")
	private SRoleDataRuleService sRoleDataRuleService;
	@Autowired
	@Qualifier("prdSoltInService")
	private PrdSoltInService prdSoltInService;

	/**
	 * 列表数据查询
	 * 
	 * @param page
	 * @param size
	 * @return
	 */
	@PostMapping(value = "/prd/solt/ins")
	public @ResponseBody ResponseData<List<PrdSoltInVO>> queryPrdSoltInAll(@RequestBody PrdSoltInVO vo) {
		// 根据用户角色获取用户权限方案
		List<PrdSoltInVO> outputVo = null;
		Map<String,String> dataRuleTypeMap = sRoleDataRuleService.getDataRuleType(httpRequest.getRequestURI(), getUserRoles());
		vo.setPrdCodebyBaseInfo(dataRuleTypeMap == null ? null:dataRuleTypeMap.get(PubConstant.PRD_CODE));
		DataRuleType dataRuleType = DataRuleType.getDataRuleType(dataRuleTypeMap == null ? null:dataRuleTypeMap.get(PubConstant.PERMIS_TYPE));
		setUserInfoToVO(vo);

		// 根据权限方案调用不同的方案进行数据查询
		switch (dataRuleType) {
		case Owner:
			outputVo = prdSoltInService.queryAllOwner(vo);
			break;
		case CurrOrg:
			outputVo = prdSoltInService.queryAllCurrOrg(vo);
			break;
		case CurrDownOrg:
			outputVo = prdSoltInService.queryAllCurrDownOrg(vo);
			break;
		default:
			outputVo = prdSoltInService.queryAllOwner(vo);
			break;
		}
		return getResponseData(outputVo);

	}

	/**
	 * 根据主键查询详情
	 * 
	 * @return
	 */
	@GetMapping(value = "/prd/solt/in/{recordKeyid}")
	public @ResponseBody ResponseData<PrdSoltInVO> queryByPk(@PathVariable("recordKeyid") String recordKeyid) {
		PrdSoltInVO inVo = new PrdSoltInVO();
		inVo.setRecordKeyid(recordKeyid);
		PrdSoltInVO outputVo = prdSoltInService.queryByPk(inVo);
		return getResponseData(outputVo);

	}

	/**
	 * 根据主键删除信息
	 * 
	 * @param prdSoltIn
	 * @return
	 */
	@DeleteMapping(value = "/prd/solt/in")
	public @ResponseBody ResponseData<Integer> deleteByPk(@RequestBody PrdSoltInVO inPrdSoltInVo) {
		int outputVo = prdSoltInService.deleteByPk(inPrdSoltInVo);
		return getResponseData(outputVo);

	}

	/**
	 * 根据主键更新信息
	 * 
	 * @param inPrdSoltInVo
	 * @return
	 */
	@PutMapping(value = "/prd/solt/in")
	public @ResponseBody ResponseData<Integer> updateByPk(@RequestBody PrdSoltInVO inPrdSoltInVo) {
		int outputVo = prdSoltInService.updateByPk(inPrdSoltInVo);
		return getResponseData(outputVo);

	}

	/**
	 * 新增数据
	 * 
	 * @param inPrdSoltInVo
	 * @return
	 */
	@PostMapping(value = "/prd/solt/in")
	public @ResponseBody ResponseData<Integer> insertPrdSoltIn(@RequestBody PrdSoltInVO inPrdSoltInVo) {
		int outputVo = prdSoltInService.insertPrdSoltIn(inPrdSoltInVo);
		return getResponseData(outputVo);

	}
}
